#ifndef OCEAN_VAGSDK_JNI_UTIL_H
#define OCEAN_VAGSDK_JNI_UTIL_H

#include <jni.h>
#include <string>

/**
 * 将 jstring 转换为 C++ 字符串。
 *
 * @param env JNI 环境指针
 * @param jstr 要转换的 jstring
 * @return 转换后的字符串
 */
std::string ConvertToStdString(JNIEnv *env, jstring jstr);

/**
 * 将字符串设置到指定对象的字段中。
 *
 * @param env JNI 环境
 * @param obj 要设置的对象
 * @param fieldID 对象的字段 ID
 * @param str 要设置为字段值的字符串
 */
void SetObjectStringField(JNIEnv *env, jobject obj, jfieldID fieldID, const std::string& str);

jobject NewArrayList(JNIEnv *env);

class JNIHandle {
private:
    JNIHandle();
    ~JNIHandle();

public:
    void Init(JNIEnv *env);
    static JNIHandle *GetInstance();

    JavaVM *jvm{};

    /** Boolean 类 */
    jclass cls_boolean{};
    jmethodID mid_boolean_init{};

    /** Long 类 */
    jclass cls_long{};
    jfieldID fid_long_value{};

    /** List 类 */
    jclass cls_list{};
    jmethodID mid_list_size{};
    jmethodID mid_list_add{};
    jmethodID mid_list_get{};

    /** ArrayList 类 */
    jclass cls_arraylist{};
    jmethodID mid_arraylist_init{};
    jmethodID mid_arraylist_add{};

    /** VagApiException 类 */
    jclass cls_vagApi_ex{};

    /** ApiResult 类 */
    jclass cls_apiResult{};
    jmethodID mid_apiResult_init{};

    /** DeviceInfo 类 */
    jclass cls_deviceInfo{};
    jmethodID mid_deviceInfo_init{};
    jfieldID fid_deviceInfo_type{};
    jfieldID fid_deviceInfoType_value{};
    jfieldID fid_deviceInfoLinkMode{};
    jfieldID fid_deviceInfoLinkMode_value{};
    jfieldID fid_deviceInfo_dev_uuid{};
    jfieldID fid_deviceInfo_ip{};
    jfieldID fid_deviceInfo_port{};
    jfieldID fid_deviceInfo_username{};
    jfieldID fid_deviceInfo_password{};

    /** DauDeviceInfo 类 */
    jclass cls_dauDeviceInfo{};
    jmethodID mid_dauDeviceInfo_init{};
    jfieldID fid_dauDeviceInfo_name{};
    jfieldID fid_dauDeviceInfo_serialnum{};
    jfieldID fid_dauDeviceInfo_version{};
    jfieldID fid_dauDeviceInfo_devType{};

    /** DevChannelInfo 类 */
    jclass cls_devChannelInfo{};
    jmethodID mid_devChannelInfo_init{};
    jfieldID fid_devChannelInfo_channelNum{};
    jfieldID fid_devChannelInfo_channelNameInfo{};

    /** ChannelNameInfo 类 */
    jclass cls_channelNameInfo{};
    jmethodID mid_channelNameInfo_init{};
    jfieldID fid_channelNameInfo_name{};
    jfieldID fid_channelNameInfo_index{};

    /** ShowStringInfo 类 */
    jclass cls_showStringInfo{};
    jmethodID mid_showStringInfo_init{};
    jfieldID fid_showStringInfo_osdInfoList{};

    /** OsdInfo 类 */
    jclass cls_osdInfo{};
    jmethodID mid_osdInfo_init{};
    jfieldID fid_osdInfo_iShowString{};
    jfieldID fid_osdInfo_iStringSize{};
    jfieldID fid_osdInfo_iShowStringTopLeftX{};
    jfieldID fid_osdInfo_iShowStringTopLeftY{};
    jfieldID fid_osdInfo_text{};

    /** PresetInfos 类 */
    jclass cls_presetInfos{};
    jmethodID mid_presetInfos_init{};
    jfieldID fid_presetInfos_presetNum{};
    jfieldID fid_presetInfos_presetInfoList{};

    /** PresetInfo 类 */
    jclass cls_presetInfo{};
    jmethodID mid_presetInfo_init{};
    jfieldID fid_presetInfo_presetId{};
    jfieldID fid_presetInfo_presetName{};

    /** SetUpAlarm 类 */
    jclass cls_setUpAlarm{};
    jmethodID mid_setUpAlarm_init{};
    jfieldID fid_setUpAlarm_dwSize{};
    jfieldID fid_setUpAlarm_byLevel{};
    jfieldID fid_setUpAlarm_byAlarmInfoType{};
    jfieldID fid_setUpAlarm_byRetAlarmTypeV40{};
    jfieldID fid_setUpAlarm_byRetVQDAlarmType{};
    jfieldID fid_setUpAlarm_byRetDevInfoVersion{};
    jfieldID fid_setUpAlarm_byFaceAlarmDetection{};
    jfieldID fid_setUpAlarm_bySupport{};
    jfieldID fid_setUpAlarm_byBrokenNetHttp{};
    jfieldID fid_setUpAlarm_wTaskNo{};
    jfieldID fid_setUpAlarm_byDeployType{};
    jfieldID fid_setUpAlarm_bySubScription{};
    jfieldID fid_setUpAlarm_byBrokenNetHttpV60{};
    jfieldID fid_setUpAlarm_byRes1{};
    jfieldID fid_setUpAlarm_byAlarmTypeURL{};
    jfieldID fid_setUpAlarm_byCustomCtrl{};
    jfieldID fid_setUpAlarm_byRes4{};

    /** VagApi 类 */
    jclass cls_vagApi{};
    jmethodID mid_vagApi_alarmCallback{};
};

#endif //OCEAN_VAGSDK_JNI_UTIL_H
